#include<stdio.h>
#include<stdlib.h>
typedef struct ListNode
{
	int _data;
	struct ListNode* _prev;
	struct ListNode* _next;
}Node;


typedef struct List
{
	Node* _head;
}List;

Node* Initialize()
{
	Node* tmp = (Node*)malloc(sizeof(Node));
	tmp->_next = tmp;
	tmp->_prev = tmp;
	return tmp;
}

void push_back(Node* head, int data)
{
	Node* tmp = (Node*)malloc(sizeof(Node));
	tmp->_data = data;
	Node* tail = head->_prev;

	tail->_next = tmp;
	tmp->_prev = tail;
	head->_prev = tmp;
	tmp->_next = head;
}

void print(Node* head)
{
	Node* cur = head->_next;
	while (cur != head)
	{
		printf("%d  ", cur->_data);
		cur = cur->_next;
	}
	printf("\n");
}

void insert(Node* head, int perso, int data)
{
	Node* cur = head->_next;
	while (cur != head)
	{
		if (perso == cur->_data)
		{
			Node* tmp = (Node*)malloc(sizeof(Node));
			tmp->_data = data;

			Node* prev = cur->_prev;

			prev->_next = tmp;
			tmp->_prev = prev;
			tmp->_next = cur;
			cur->_prev = tmp;
		}

		cur = cur->_next;
	}
}
int main()
{
	List lt;
	lt._head = Initialize();
	push_back(lt._head, 1);
	push_back(lt._head, 2);
	push_back(lt._head, 3);
	push_back(lt._head, 4);
	print(lt._head);
	insert(lt._head, 4, 3);
	insert(lt._head, 1, 99);
	print(lt._head);



}